<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>修改用户资料</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Staple Food Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template, 
	SmartPhone Compatible web template, free WebDesigns for Nokia, Samsung, LG, Sony Ericsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- Custom Theme files -->
<link href="css/bootstrap.css" type="text/css" rel="stylesheet" media="all">
<link href="css/style.css" type="text/css" rel="stylesheet" media="all">  
<link href="css/font-awesome.css" rel="stylesheet"> <!-- font-awesome icons --> 
<!-- //Custom Theme files --> 
<!-- js -->
<script src="js/jquery-2.2.3.min.js"></script>  
<!-- //js -->
<!-- web-fonts -->   
<link href="http://fonts.googleapis.com/css?family=Berkshire+Swash" rel="stylesheet"> 
<link href="http://fonts.googleapis.com/css?family=Yantramanav:100,300,400,500,700,900" rel="stylesheet">
<!-- //web-fonts -->
</head>
<body> 
	<!-- banner -->
	<div class="banner about-w3bnr">
		<!-- header -->
		<%@ include file="../jsp/userHeader2.jsp" %>
		<!-- //header-end --> 
		<!-- banner-text -->
		<div class="banner-text">	
			<div class="container">
				<h2>Delicious food from the <br> <span>
				最好的美食.</span>
				</h2> 
			</div>
		</div>
	</div>
	<!-- //banner -->    
	<!-- breadcrumb -->  
	<div class="container">	
		<ol class="breadcrumb w3l-crumbs">
			<li><a href="${pageContext.request.contextPath}/userIndex.action">
					<i class="fa fa-home"></i> 主页
				</a>
			</li>
			<li class="active">用户资料</li>
			<li class="active">修改用户资料</li>
		</ol>
	</div>
	<div class="codes">
		<div class="container">   
			<div class="grid_3 grid_4">
				<h3 class="w3ls-hdg">修改用户资料</h3>
				<div class="tab-content">
					<div class="tab-pane active" id="horizontal-form">
						<div class="form-horizontal">
							<input hidden="hidden" id="hidUserId" value="${itemList[0].userId}">
							<div class="form-group">
								<label for="disabledinput" class="col-sm-2 control-label">当前登录名</label>
								<div class="col-sm-8">
									<input disabled="disabled" type="text" class="form-control1" id="txtLoginName" name="txtLoginName" value="${sessionScope.login.loginName}">
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword" class="col-sm-2 control-label">用户名</label>
								<div class="col-sm-8">
									<input type="text" class="form-control1" id="txtUserName" name="txtUserName" value="${itemList[0].userName}" placeholder="用户名">
								</div>
							</div>
							<div class="form-group">
								<label for="selector1" class="col-sm-2 control-label">性别</label>
								<div class="col-sm-8"><select name="txtGender" id="txtGender" class="form-control1">
									<option>不选择</option>
									<option value="男">男</option>
									<option value="女">女</option>
								</select></div>
								<script type="text/javascript">
									$("#txtGender").val("${itemList[0].gender}");
								</script>
							</div>
							<div class="form-group">
								<label for="inputPassword" class="col-sm-2 control-label">电话/手机号</label>
								<div class="col-sm-8">
									<input type="text" class="form-control1" id="txtPhoneNumber" name="txtPhoneNumber" placeholder="电话/手机号" value="${itemList[0].phoneNumber}">
								</div>
							</div>
							<div class="form-group">
								<label for="selector1" class="col-sm-2 control-label">店铺</label>
								<div class="col-sm-8"><select name="txtStoreId" id="txtStoreId" class="form-control1">
								</select></div>
							</div>
							<div class="form-group">
								<label for="inputPassword" class="col-sm-2 control-label">备注</label>
								<div class="col-sm-8">
									<input type="text" class="form-control1" id="txtRemark" name="txtRemark" placeholder="备注" value="${itemList[0].remark}">
								</div>
							</div>
							<div class="form-group">
						       <div class="col-lg-offset-1 col-lg-9">
						       <div id ="Modify1" >
						       	 <c:if test="${!empty itemList[0].userName}">
						       	 	<button onclick="saveUser()" class="btn btn-primary">保存</button>
						       	 </c:if>
						         <c:if test="${empty itemList[0].userName}">
						       	 	<button onclick="addUser()" class="btn btn-primary">添加</button>
						       	 </c:if>                            
                        		 <button class="btn btn-default" onclick="cancelSaveUser()" >取消</button>
						       </div>
						        </div>
						    </div>
						</div>
					</div>
				</div>
			</div>  
		</div> 
	</div>   
	
	<!-- //contact -->   
	
	<!-- footer -->
	<%@ include file="../jsp/userFooter.jsp" %>
	<!-- //footer -->
	<!-- cart-js -->
	<script src="js/minicart.js"></script>
	<script>
        w3ls.render();
        w3ls.cart.on('w3sb_checkout', function (evt) {
        	var items, len, i;

        	if (this.subtotal() > 0) {
        		items = this.items();

        		for (i = 0, len = items.length; i < len; i++) { 
        		}
        	}
        });
    </script>  
	<!-- //cart-js -->	
	<!-- start-smooth-scrolling -->
	<script src="js/SmoothScroll.min.js"></script>  
	<script type="text/javascript" src="js/move-top.js"></script>
	<script type="text/javascript" src="js/easing.js"></script>	
	<script type="text/javascript">
			jQuery(document).ready(function($) {
				$(".scroll").click(function(event){		
					event.preventDefault();
			
			$('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
				});
			});
	</script>
	<!-- //end-smooth-scrolling -->	  
	<!-- smooth-scrolling-of-move-up -->
	<script type="text/javascript">
		$(document).ready(function() {
			myLoad();
			getService();
			$().UItoTop({ easingType: 'easeOutQuart' });
			
		});
		function myLoad() {
			  ${alertMsg}
			}
		function addUser() {
			var userId = $("#hidUserId").val();
			var userName = $("#txtUserName").val();
			var storeId = $('#txtStoreId option:selected').val();
			//var userNameName = $("*[name='txtUserName']").val(); //获取vlaue值
			var phoneNumber = $("#txtPhoneNumber").val();
			var gender = $('#txtGender option:selected').val();
			var remark = $("#txtRemark").val();
			var user_json = {
			   "userId":userId,
	           "userName":userName,
	           "storeId":storeId,
	           "phoneNumber":phoneNumber,
	           "gender":gender,
	           "remark":remark
	           }      
			//js对象转换成JSON字符串  
			var jason_str = JSON.stringify(user_json);
			
			$.ajax({  
		        url :"${pageContext.request.contextPath }/addUser.action",   
		        cache : true,  
		        type : "post",  
		        datatype : "json",  
		        contentType : "application/json; charset=utf-8",  
		        data : jason_str,  
		        success : function(data){  
		            if(data == 0){  
		                alert("添加出现未知错误！"); 
		            } else{   
		            	alert("添加成功！");
	                }  
	            window.location.reload();
	            }  
		    });
		}
		function saveUser() {
			var userId = $("#hidUserId").val();
			var userName = $("#txtUserName").val();
			var storeId = $('#txtStoreId option:selected').val();
			//var userNameName = $("*[name='txtUserName']").val(); //获取vlaue值
			var phoneNumber = $("#txtPhoneNumber").val();
			var gender = $('#txtGender option:selected').val();
			var remark = $("#txtRemark").val();
			var user_json = {
			   "userId":userId,
	           "userName":userName,
	           "storeId":storeId,
	           "phoneNumber":phoneNumber,
	           "gender":gender,
	           "remark":remark
	           }      
			//js对象转换成JSON字符串  
			var jason_str = JSON.stringify(user_json);
			$.ajax({  
		        url :"${pageContext.request.contextPath }/saveUser.action",   
		        cache : true,  
		        type : "post",  
		        datatype : "json",  
		        contentType : "application/json; charset=utf-8",  
		        data : jason_str,  
		        success : function(data){  
		            if(data == 0){  
		                alert("修改出现未知错误！"); 
		            } else{   
		            	alert("修改成功！");
	                }  
	            window.location.reload();
	            }  
		    });
		}
		function cancelSaveUser(){
			$("#hidUserId").val("");
			$("#txtUserName").val("");
			$("#txtStoreId").val("");
			$('#txtGender').val("");
			$("#txtPhoneNumber").val("");
			$('#txtRemark').val("");
		}
		function getService() {
			var str = null;
			$("select[name=txtStoreId]").empty();      //清空  
		  $.ajax({  
		      url :"${pageContext.request.contextPath }/searchAllStore.action",   
		      cache : true,  
		      type : "post",  
		      datatype : "json",  
		      contentType : "application/json; charset=utf-8",  
		      data : "",  
		      success : function(data){
		    	  for (var i in data) {  
		              str += "<option value='"+ data[i].storeId + "'>" +data[i].storeName+"</option>";
		          } 
		    	  $("#txtStoreId").prepend(str);
		      },  
		      error: function (msg) {  
		          alert("出错了！");  
		      }  
		  });
		}
	</script>
	<!-- //smooth-scrolling-of-move-up --> 
	<!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="js/bootstrap.js"></script>
</body>
</html>